extends IEventBehavior


class_name HitReflect
"""
击中时反弹
"""


## 需要检测的碰撞层
@export_flags_2d_physics  var hit_layer: int  = 0


func support() -> Array:
    return [CharacterUnit.Event.ON_HIT_SOMETHING]

## 处理武器命中事件,返回是否取消销毁子弹
func do_event(character: CharacterComponent, v: EffectValue, e: CharacterEvent) -> void:
    if BehaviorHelper.is_layer(hit_layer, e):
        var move: MoveComponent = e.meta.projectile.element.subassembly("Move")
        if move:
            var refect_direction: Vector2 = move.direction.bounce(e.meta.normal)
            move.turn(refect_direction)
            v.value -= 1
            e.cancel()
